<template>
  <el-card shadow="never">
    <div slot="header">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>用户管理</el-breadcrumb-item>
        <el-breadcrumb-item>用户列表</el-breadcrumb-item>
      </el-breadcrumb>
      <!-- 主题区域 -->
    </div>
    <!-- 过滤区域 -->
    <div class="filter-bar">
      <el-form :model="searchForm" label-width="80px" :inline="true" size="small" ref="form">
        <el-form-item label="用户id">
          <el-input v-model="searchForm.user_id"></el-input>
        </el-form-item>
        <el-form-item label="支付状态">
          <el-select v-model="searchForm.pay_status">
            <el-option value label="全部状态"></el-option>
            <el-option value="0" label="已付款"></el-option>
            <el-option value="1" label="未付款"></el-option>
          </el-select>
          <el-form-item label="发货装态">
            <el-select v-model="searchForm.id_send">
              <el-option value label="全部状态"></el-option>
              <el-option value="是" label="是"></el-option>
              <el-option value="否" label="否"></el-option>
            </el-select>
          </el-form-item>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getOrderList">查询</el-button>
          <el-button @click="resetSearch">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格区域 -->
    <div class="table-box">
      <el-table :data="orderList" border>
        <el-table-column label="序号" type="index" width="60px"></el-table-column>
        <el-table-column label="订单编号" prop="order_number" width="300px"></el-table-column>
        <el-table-column label="订单价格" prop="order_price" width="100px"></el-table-column>
        <el-table-column label="用户ID" prop="user_id" width="100px"></el-table-column>
        <el-table-column label="是否付款" prop="pay_status">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status === '1'">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" plain v-if="scope.row.is_send === '是'">已发货</el-button>
            <el-button size="mini" type="warning" plain v-if="scope.row.is_send === '否'">未发货</el-button>
          </template>
        </el-table-column>
        <el-table-column label="下单时间" prop="create_time">
          <template slot-scope="scope">{{scope.row.create_time | formateTime}}</template>
        </el-table-column>
        <el-table-column label="操作" width="125px">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-edit"
              @click="editOrder(scope.row)"
              circle
            ></el-button>
            <el-button
              size="mini"
              type="success"
              icon="el-icon-location"
              @click="seeExpress(scope.row)"
              circle
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页器 -->
      <el-pagination
        background
        layout="total, prev, pager, next, jumper"
        :total="total"
        :page-size="searchForm.pagesize"
        :page-sizes="[1, 2, 3, 4, 5, 6]"
        @current-change="pageChange"
      ></el-pagination>
    </div>
    <!-- 物流信息弹框 -->
    <el-dialog title="物流信息" :visible.sync="addressDialogShow" width="60%">
      <el-row>
        <el-col :span="20" :offset="3">
          <el-timeline :reverse="false">
            <el-timeline-item
              v-for="(item,idx) in expressInfo"
              :key="idx"
              :timestamp="item.time"
              :size="item.size"
              :icon="item.icon"
              :color="item.color"
            >
              <!-- content -->
              {{item.context}}
            </el-timeline-item>
          </el-timeline>
        </el-col>
      </el-row>
      <span slot="footer">
        <el-button type="primary" @click="addressDialogShow = false">OK</el-button>
      </span>
    </el-dialog>
    <!-- 修改地址弹窗 -->
    <el-dialog
      title="修改收货地址"
      :visible.sync="editAddressDialogShow"
      width="40%"
      @close="$refs.addressForm.resetFields()"
    >
      <el-form
        :model="addressForm"
        ref="addressForm"
        :rules="addressFormRules"
        label-width="80px"
        :inline="false"
        size="normal"
      >
        <el-form-item label="省县市" prop="adress_list">
          <el-cascader :options="cityData" v-model="addressForm.address_list"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="detail_info">
          <el-input v-model="addressForm.detail_info"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="editAddressDialogShow = false">立即创建</el-button>
          <el-button @click="editAddressDialogShow = false">取消</el-button>
        </el-form-item>
      </el-form>

      <span slot="footer">
        <!-- <el-button type="primary" @click="addressDialogShow = false">OK</el-button> -->
      </span>
    </el-dialog>
  </el-card>
</template>

<script>
import cityData from "../cityData/citydata";
// console.log(cityData);
export default {
  data() {
    return {
      //查询条件
      searchForm: {
        query: "",
        pagenum: 1,
        pagesize: 10,
      },
      //订单列表数据
      orderList: [],
      //   物流信息
      expressInfo: [],
      cityData,
      //数据总条数
      total: 0,
      addressDialogShow: false,
      addressForm: {
        address_list: [],
        detail_info: "",
      },
      editAddressDialogShow: false,
      addressFormRules: {
        address_list: [
          { required: true, message: "请选择省县市", trigger: "blur" },
        ],
        detail_info: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getOrderList();
  },
  methods: {
    async getOrderList() {
      const { data: res } = await this.$axios.get("orders", {
        params: this.searchForm,
      });

      if (res.meta.status !== 200) {
        return this.$message.error("获取订单列表数据失败!");
      }

      this.total = res.data.total;
      this.orderList = res.data.goods;
    },
    handleSizeChange(newSize) {
      this.searchForm.pagesize = newSize;
      this.getOrderList();
    },
    handleCurrentChange(newPage) {
      this.searchForm.pagenum = newPage;
      this.getOrderList();
    },
    ///////////////////重置表单///////////////////////////////
    resetSearch() {
      this.$refs.form.resetFields();
    },
    pageChange(val) {
      this.searchForm.pagenum = val;
      this.getOrderList();
    },
    // 编辑按钮事件
    editOrder(row) {
      // console.log(row);
      this.editAddressDialogShow = true;
    },
    // 查看物流按钮事件
    seeExpress(row) {
      if (row.is_send == "是") {
        this.addressDialogShow = true;
        //发货了,储存物流信息
        this.expressInfo = [
          {
            icon: "el-icon-location",
            color: "#0bbd87",
            size: "large",
            time: "2018-05-10 09:39:00",
            ftime: "2018-05-10 09:39:00",
            context: "已签收,感谢使用顺丰,期待再次为您服务",
            location: "",
          },
          {
            time: "2018-05-10 08:23:00",
            ftime: "2018-05-10 08:23:00",
            context:
              "[北京市]北京海淀育新小区营业点派件员 顺丰速运 95338正在为您派件",
            location: "",
          },
          {
            time: "2018-05-10 07:32:00",
            ftime: "2018-05-10 07:32:00",
            context: "快件到达 [北京海淀育新小区营业点]",
            location: "",
          },
          {
            time: "2018-05-10 02:03:00",
            ftime: "2018-05-10 02:03:00",
            context:
              "快件在[北京顺义集散中心]已装车,准备发往 [北京海淀育新小区营业点]",
            location: "",
          },
          {
            time: "2018-05-09 23:05:00",
            ftime: "2018-05-09 23:05:00",
            context: "快件到达 [北京顺义集散中心]",
            location: "",
          },
          {
            time: "2018-05-09 21:21:00",
            ftime: "2018-05-09 21:21:00",
            context: "快件在[北京宝胜营业点]已装车,准备发往 [北京顺义集散中心]",
            location: "",
          },
          {
            time: "2018-05-09 13:07:00",
            ftime: "2018-05-09 13:07:00",
            context: "顺丰速运 已收取快件",
            location: "",
          },
          {
            time: "2018-05-09 12:25:03",
            ftime: "2018-05-09 12:25:03",
            context: "卖家发货",
            location: "",
          },
          {
            time: "2018-05-09 12:22:24",
            ftime: "2018-05-09 12:22:24",
            context: "您的订单将由HLA（北京海淀区清河中街店）门店安排发货。",
            location: "",
          },
          {
            time: "2018-05-08 21:36:04",
            ftime: "2018-05-08 21:36:04",
            context: "商品已经下单",
            location: "",
          },
        ];
      } else {
        this.$notify.warning({
          title: "警告!",
          message: "商品未发货",
        });
      }
    },
  },
};
</script>

<style lang="less" scoped>
</style>